package com.ssmsq.multidatabase.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ssmsq.multidatabase.entity.SysUser;
import com.ssmsq.multidatabase.mapper.SysUserMapper;
import com.ssmsq.multidatabase.service.SysRoleService;
import com.ssmsq.multidatabase.service.SysUserService;
import com.ssmsq.multidatabase.service.YwzxXiangmuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author sss
 */
@DS("master")
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Resource
    private YwzxXiangmuService ywzxXiangmuService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean testRoll(Integer a, Integer b) {
        boolean flag = false;
        try {
            Date date = new Date();
            SysUser sysUser = new SysUser();
            sysUser.setName("iasp_" + date);
            sysUser.setCreateUser("ssm");
            sysUser.setCreateTime(date);
            flag = save(sysUser);

            if(a != null && a == 0) {
                flag = ywzxXiangmuService.saveOne(b, date);
            }
            if(!flag) {
                throw new RuntimeException();
            }
        } catch (Exception e) {
            throw e;
        }
        return flag;
    }
}
